<template>
  <a-card style="width:100%">
    <a-form :form="form">
      <a-row>
        <a-col :md="8" :sm="12">
          <a-form-item label="源年级"
            :labelCol="{span: 7,offset: 1}"
            :wrapperCol="{span: 15, offset: 1}">
            <a-select v-decorator="['sourceSsnj',
              {
                rules: [{ required: true, message: '请选择源年级!' }],
              }]">
              <a-select-option v-for="i in TYPE0126" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
            </a-select>
          </a-form-item>
        </a-col>
        <a-col :md="8" :sm="12">
          <a-form-item label="使用年级"
            :labelCol="{span: 7,offset: 1}"
            :wrapperCol="{span: 15, offset: 1}">
            <a-select v-decorator="['targetSsnj',
              {
                rules: [{ required: true, message: '请选择使用年级!' }],
              }]">
              <a-select-option v-for="i in TYPE0126" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
            </a-select>
          </a-form-item>
        </a-col>
        <a-col :md="6" :sm="24">
          <a-button type="primary" :loading="loading" @click="batchCopy" style="margin:0 10px">批量复制</a-button>
        </a-col>
      </a-row>
      <a-alert message="温馨提示：请选择复制后的培养方案使用年级。该操作将会清除已制定好的新年级培养方案，请务必在年级培养方案制定前进行该操作。" type="error" />
    </a-form>
  </a-card>
</template>

<script>
import { mapState } from 'vuex'

export default {
  data () {
    return {
      selectMenu: {},
      searchParams: {},
      form: this.$form.createForm(this),
      loading: false
    }
  },
  computed: {
    ...mapState({
      TYPE0126: state => state.app['TYPE0126']
    })
  },
  created () {
    this.$store.dispatch('app/setDictionary', 'TYPE0126')
    this.$store.dispatch('app/sysInfo').then(data => {
      this.$nextTick(() => {
        this.form.setFieldsValue({sourceSsnj: data.currentGrade,targetSsnj: data.currentGrade})
      })
    })
  },
  methods: {
    batchCopy () {
      this.form.validateFields((err, values) => {
        if (err) {
          return
        }
        this.$confirm({
          title: '批量复制将会覆盖已经创建的培养方案，确定要执行此操作吗',
          content: '批量复制将会覆盖已经创建的培养方案，确定要执行此操作吗',
          centered: true,
          onOk: () => {
            this.loading = true
            this.$api.cultivate.schemeBatchCopy(values).then(res => {
              this.$message.success(res.msg)
            }).finally(() => {
              this.loading = false
            })
          },
          onCancel: () => {
            return
          }
        })
      })
    }
  }
}
</script>

<style>

</style>
